package system_configuration_service

import (
	"time"

	"gitee.com/Luna-CY/Golang-Project-Template/internal/interface/dao"

	"gitee.com/Luna-CY/Golang-Project-Template/internal/context"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/errors"
	"gitee.com/Luna-CY/Golang-Project-Template/model"
)

func (cls *Configuration) SafeGetAllConfiguration(ctx context.Context, options ...dao.SystemConfigurationOption) ([]*model.SystemConfiguration, errors.Error) {
	var now = time.Now().Unix()

	options = append(options, dao.SystemConfigurationOptionWithEffectTimeLessThanOrIsZero(now), dao.SystemConfigurationOptionWithExpiredTimeGreaterThanOrIsZero(now), dao.SystemConfigurationOptionWithStatus(model.SystemConfigurationStatusEnabled))

	data, err := cls.configuration.SafeTakeAllConfiguration(ctx, options...)
	if err != nil {
		return nil, err.Relation(errors.ErrorServerInternalError("ISC_ON.C_ON.SGAC_ON.124750", "获取配置失败"))
	}

	return data, nil
}
